﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Management;
using System.Text;
using WMI.NET.Abstracts;
using WMI.NET.CIM;

namespace WMI.NET.ComputerSystemHardware.MotherboardControllerPort
{
    /// <summary>
    /// The Win32_PhysicalMemory WMI class represents a physical memory device located on a computer system and available to the operating system.
    /// </summary>
    public class Win32_PhysicalMemory : CIM_PhysicalMemory
    {
        private string _DeviceLocator;
        private Nullable<UInt16> _InterleaveDataDepth;
        private Nullable<UInt16> _TypeDetail;

        /// <summary>
        /// Label of the socket or circuit board that holds the memory.
        /// Example: "SIMM 3"
        /// </summary>
        public string DeviceLocator { get { return _DeviceLocator; } }

        /// <summary>
        /// Unsigned 16-bit integer maximum number of consecutive rows of data that are accessed in a single interleaved transfer from the memory device. If the value is 0 (zero), the memory is not interleaved.
        /// </summary>
        public Nullable<UInt16> InterleaveDataDepth { get { return _InterleaveDataDepth; } }

        /// <summary>
        /// Type of physical memory represented.
        /// </summary>
        public Nullable<UInt16> TypeDetail { get { return _TypeDetail; } } //TODO enum

        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public Win32_PhysicalMemory(ManagementBaseObject mbo)
            : base(mbo)
        {
            _DeviceLocator = mbo.GetStringValue("DeviceLocator");
            _InterleaveDataDepth = mbo.GetUshortValue("InterleaveDataDepth");
            _TypeDetail = mbo.GetUshortValue("TypeDetail");
        }

    }

    /// <summary>
    /// 
    /// </summary>
    public class GetWin32_PhysicalMemories : Win32Collection<Win32_PhysicalMemory>
    {

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ReadOnlyCollection<Win32_PhysicalMemory> GetCollection()
        {
            List<Win32_PhysicalMemory> tempCollection = new List<Win32_PhysicalMemory>();

            foreach (var s in searcher.Get())
            {
                Win32_PhysicalMemory tempListItem = new Win32_PhysicalMemory(s);
                tempCollection.Add(tempListItem);
            }

            return tempCollection.AsReadOnly();
        }

        /// <summary>
        /// 
        /// </summary>
        public GetWin32_PhysicalMemories() : base("SELECT * FROM Win32_PhysicalMemory") { }

    }


}


